-
Notifications
You must be signed in to change notification settings - Fork 411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add decrease interface for aggregation #9737
Conversation
@@ -66,7 +66,7 @@ class AggregateFunctionForEach final | |||
AggregateFunctionForEachData & ensureAggregateData( | |||
AggregateDataPtr __restrict place, | |||
size_t new_size, | |||
Arena & arena) const | |||
Arena * arena) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think no need to change it now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think no need to change it now?
revoked
namespace DB | ||
{ | ||
template <typename T> | ||
struct SingleValueDataFixedForWindow : public SingleValueDataFixed<T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this struct need inherit SingleValueDataFixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think SingleValueDataFixedForWindow
can not just inherit the ser/deser functions from SingleValueDataFixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this struct need inherit
SingleValueDataFixed
we now delete the inheritence.
using Self = SingleValueDataStringForWindow; | ||
|
||
// TODO use std::string is inefficient | ||
mutable std::multiset<std::string> saved_values; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is collator take affect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is collator take affect?
Collator comparison is added now.
if constexpr (is_add) | ||
{ | ||
this->addCounter(place); | ||
this->setFlag(place); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but why do we need to inherit AggregateFunctionNullBase
|
||
if (result_is_nullable && need_counter) | ||
{ | ||
auto tmp = prefix_size; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why we still need null flag
saved_values.erase(iter); | ||
} | ||
|
||
void changeIfLess(const IColumn & column, size_t row_num, Arena *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can define an add
method, both changeIfLess
and changeIfGreater
can call add
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can define an
add
method, bothchangeIfLess
andchangeIfGreater
can calladd
done
if constexpr (is_min) | ||
iter = saved_values.begin(); | ||
else | ||
iter = std::prev(saved_values.end()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just use iter = saved_values.rbegin()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just use iter = saved_values.rbegin()?
done
{} | ||
|
||
// TODO use std::string is inefficient | ||
std::string value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use StringRef or std::string_view
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use StringRef or std::string_view
Using StringRef now.
@@ -91,13 +90,23 @@ class AggregateFunctionNullBase : public IAggregateFunctionHelper<Derived> | |||
} | |||
|
|||
public: | |||
explicit AggregateFunctionNullBase(AggregateFunctionPtr nested_function_) | |||
explicit AggregateFunctionNullBase(AggregateFunctionPtr nested_function_, bool need_counter = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why need_counter is still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why need_counter is still needed?
deleted
, collator(collator_) | ||
{} | ||
|
||
// TODO use StringRef is inefficient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the todo mean, is there any more efficient implement here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the todo mean, is there any more efficient implement here?
It can be deleted now.
mutable multiset saved_values; | ||
TiDB::TiDBCollatorPtr collator{}; | ||
|
||
void saveValue(StringRef value) { saved_values.insert(StringWithCollator(value, collator)); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void saveValue(StringRef value) { saved_values.insert(StringWithCollator(value, collator)); } | |
void saveValue(StringRef & value) { saved_values.insert(StringWithCollator(value, collator)); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
switch (prefix_size) | ||
{ | ||
case 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just use an array like [sizeof(uint64), sizeof(uint64), sizeof(uint64), 9, sizeof(uint64), 10, 12, 14], so the result_prefix_size = array[prefix_size], or use a static array so it can be init at runtime without assuming sizeof(uint64) == 8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just use an array like [sizeof(uint64), sizeof(uint64), sizeof(uint64), 9, sizeof(uint64), 10, 12, 14], so the result_prefix_size = array[prefix_size], or use a static array so it can be init at runtime without assuming sizeof(uint64) == 8
done
@@ -505,4 +504,197 @@ class AggregateFunctionNullVariadic final | |||
std::array<char, MAX_ARGS> is_nullable; /// Plain array is better than std::vector due to one indirection less. | |||
}; | |||
|
|||
// Make the prefix_size >= sizeof(UInt64) and could fit the align size | |||
inline size_t enlarge_prefix_size(size_t prefix_size) noexcept |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like as the function name, it should be enlargePrefixSize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like as the function name, it should be
enlargePrefixSize
done
fmt::format("Cannot allocate memory (posix_memalign), size: {}, alignment: {}.", size, alignment), | ||
ErrorCodes::CANNOT_ALLOCATE_MEMORY, | ||
res); | ||
buf = new_buf; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The buf
is always nullptr when this function is called?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
buf
is always nullptr when this function is called?
yes
dbms/src/Common/AlignedBuffer.h
Outdated
public: | ||
AlignedBuffer() = default; | ||
AlignedBuffer(size_t size, size_t alignment); | ||
AlignedBuffer(AlignedBuffer && old) noexcept { std::swap(buf, old.buf); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function seems useless, because there is no guarantee that the alignment is the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function seems useless, because there is no guarantee that the alignment is the same?
deleted
{ | ||
assert(prefix_size != 0); | ||
static_assert((sizeof(prefix_size_look_up_table) / sizeof(UInt64)) == 7); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
asdd another static_assert to make sure sizeof(UInt64) == 8?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
asdd another static_assert to make sure sizeof(UInt64) == 8?
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: guo-shaoge, windtalker The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
What problem does this PR solve?
Issue Number: ref #7376
Problem Summary:
What is changed and how it works?
Check List
Tests
Side effects
Documentation
Release note